package testDemo.Test8;

import java.io.*;
import java.net.ServerSocket;

/**
 * @author win10
 */
public class Server{
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10066);
//        BufferedReader bis = new BufferedReader(new InputStreamReader(ss.accept().getInputStream()));
//        BufferedWriter bos = new BufferedWriter(new FileWriter("b.txt"));
//        String line;
//        while((line=bis.readLine())!=null) {
//            bos.write(line);
//            bos.newLine();
//            bos.flush();
//        }
        DataInputStream dis=new DataInputStream(new BufferedInputStream(ss.accept().getInputStream()));
        DataOutputStream dos=new DataOutputStream(new BufferedOutputStream(new FileOutputStream("b.txt")));
        System.out.println(dis.readUTF());
        byte[] bytes = new byte[1024];
        int line;
        while((line=dis.read(bytes))!=-1){
            dos.write(bytes,0,line);
            dos.flush();
        }
        ss.close();
    }
}
